package JUC.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author mubei
 * @date 2021/11/23
 * @description
 */
public class Demo02 {

    public static void main(String[] args) {
        Phone4 phone3 =new Phone4();

        new Thread(()->{
            phone3.sms();
        },"A").start();
        new Thread(()->{
            phone3.sms();
        },"B").start();
    }
}

class Phone4{
    Lock lock = new ReentrantLock();

    public  void sms(){
        lock.lock();
        try{
            System.out.println(Thread.currentThread().getName()+"sms");
            call();
        }finally{
            lock.unlock();
        }

    }

    public  void call(){
        lock.lock();
        try{
            System.out.println(Thread.currentThread().getName()+"call");
        }finally{
            lock.unlock();
        }

    }
}
